package com.zbcz.crm

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.zbcz.crm.databinding.ActivityHomeBinding
import com.zbcz.crm.sp.SharedPreferencesManager
import com.zbcz.crm.util.onSingleClick

class HomeActivity : BaseActivity() {

    private lateinit var mBinding: ActivityHomeBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityHomeBinding.inflate(layoutInflater)
        setContentView(mBinding.root)
        init()
    }

    private fun init() {
        mBinding.tvVisitListQuery.onSingleClick {
            startActivity(Intent(this, VisitOrderListActivity::class.java))
        }
        mBinding.ivVisitListQuery.onSingleClick {
            startActivity(Intent(this, VisitOrderListActivity::class.java))
        }
        mBinding.tvAddVisitList.onSingleClick {
            startActivity(Intent(this, VisitorAddActivity::class.java))
        }
        mBinding.ivAddVisitOrder.onSingleClick {
            startActivity(Intent(this, VisitorAddActivity::class.java))
        }
        mBinding.tvAddUser.onSingleClick {
            startActivity(Intent(this, CustomerAddActivity::class.java))
        }
        mBinding.ivAddUser.onSingleClick {
            startActivity(Intent(this, CustomerAddActivity::class.java))
        }
        mBinding.ivAddContacts.onSingleClick {
            startActivity(Intent(this, ContactsAddActivity::class.java))
        }
        mBinding.tvAddContacts.onSingleClick {
            startActivity(Intent(this, ContactsAddActivity::class.java))
        }
        mBinding.tvProjectQuery.onSingleClick {
            startActivity(Intent(this, ProjectQueryActivity::class.java))
        }
        mBinding.ivProjectQuery.onSingleClick {
            startActivity(Intent(this, ProjectQueryActivity::class.java))
        }

        mBinding.tvProductQuery.onSingleClick {
            startActivity(Intent(this, ProductQueryActivity::class.java))
        }
        mBinding.ivProductQuery.onSingleClick {
            startActivity(Intent(this, ProductQueryActivity::class.java))
        }

        mBinding.tvAccessoriesQuery.onSingleClick {
            startActivity(Intent(this, AccessoriesQueryActivity::class.java))
        }
        mBinding.ivAccessoriesQuery.onSingleClick {
            startActivity(Intent(this, AccessoriesQueryActivity::class.java))
        }
//        Glide.with(this)
//            .load(SharedPreferencesManager.getUserInfo(this)?.avatar)
//            .apply(RequestOptions.circleCropTransform())
//            .into(mBinding.ivAvatar)
    }


    private var doubleBackToExitPressedOnce = false
    override fun onBackPressed() {
        if (doubleBackToExitPressedOnce) {
            super.onBackPressed()
            return
        }

        this.doubleBackToExitPressedOnce = true
        Toast.makeText(this, "再按一次退出应用", Toast.LENGTH_SHORT).show()

        Handler(Looper.getMainLooper()).postDelayed({
            doubleBackToExitPressedOnce = false
        }, 2000) // 2秒后重置状态
    }
}